import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { UsersModule } from '../users/users.module';
import { AuthService } from './auth.service';
import { JwtStrategy } from './jwt.strategy';
import { UsersService } from 'src/users/users.service';
import { LocalStrategy } from './local.strategy';
import { AuthController } from './auth.controller';
import * as passport from 'passport';
import { ResponseModule } from 'src/response/response.module';
import { ResponseService } from 'src/response/response.service';
@Module({
  imports: [
    ResponseModule,
    UsersModule,
    PassportModule,
    JwtModule.register({
      secret: 'op;wqekfdsdfhgjdsqwygjj123',
      signOptions: { expiresIn: '24h' },
    }),
    PassportModule.register({ session: true })
  ],
  controllers: [AuthController],
  providers: [AuthService,LocalStrategy, JwtStrategy, UsersService,ResponseService],
  exports: [AuthService],
})
export class AuthModule {
  constructor(private authService: AuthService) {
    passport.serializeUser((user, done) => {
      done(null, user.userid);
    });

    passport.deserializeUser(async (id, done) => {
      const user = await this.authService.findUserById(id);
      done(null, user);
    });
  }
}
